import { Request, Response, NextFunction } from "express";
import ResponseDTO from "@/dto/ResponseDTO";
// 成功处理中间件
export const responseMiddleWare = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  if (res.locals.error) {
    res
      .status(200)
      .json(ResponseDTO.error(500, res.locals.error.message || "请求失败"));
    next();
  } else {
    console.log(res.locals.data);
    res.status(200).json(ResponseDTO.success(res.locals.data));
    next();
  }
};
